using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebReference;

public partial class payment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int cardTypeNum;
        string cardnum = Request.QueryString["cardnum"];
        string cardType = Request.QueryString["cardtype"];
        string expiredate = Request.QueryString["expiredate"];
        string amount = Request.QueryString["amount"];
        string calleridnum = Request.QueryString["calleridnum"];
        string accountID = Request.QueryString["accountnum"];

        if (int.TryParse(cardType, out cardTypeNum))
        {
            if ((cardTypeNum > 0) && (cardTypeNum < 4))
            {
                PaymentInfoEx paymentinfo = new PaymentInfoEx();
                paymentinfo.customerid = accountID;
                paymentinfo.username = accountID;
                paymentinfo.cardtype = getCardType(cardTypeNum);
                paymentinfo.cardtypenum = getCardTypeNum(cardTypeNum);
                paymentinfo.remark = calleridnum;
                PaymentService payment = new PaymentService();

                string strResult = payment.TestPayment("reg", cardnum, expiredate, double.Parse(amount), paymentinfo, accountID);
                Response.Write(strResult);
            }
            else
            {
                Response.Write("2 error");
            }
        }
        else
        {
            Response.Write("1 error");
        }
    }

    private paymenttype getCardTypeNum(int cardTypeNum)
    {
        paymenttype cardTypeNumber;
        switch (cardTypeNum)
        { 
            case 1:
                cardTypeNumber = paymenttype.MasterCard;
                break;
            case 2:
                cardTypeNumber = paymenttype.VISA;
                break;
            case 3:
                cardTypeNumber = paymenttype.Amex;
                break;  
            default :
                cardTypeNumber = paymenttype.Amex;
                break;
        }
        return cardTypeNumber;
    }

    private string getCardType(int cardTypeNum)
    {
        string cardType;
        switch (cardTypeNum)
        {
            case 1:
                cardType = "MasterCard";
                break;
            case 2:
                cardType = "VISA";
                break;
            case 3:
                cardType = "Amex";
                break;
            default:
                cardType = "";
                break;
        }
        return cardType;
    }
}
